import unittest
import sys
import time
import os
import HwTestReport
import Common

class Program:
    def __init__(self):
        self.run()

    def run(self):
        suite = unittest.defaultTestLoader.discover(os.getcwd(), "test_*.py")
        # 取当前路径
        curPath = sys.path[0]
        # 取当前时间
        now = time.strftime("%Y-%m-%d-%H %M %S", time.localtime(time.time()))
        # 文件名
        filename = curPath + '/report/' + now + 'report.html'
        # 判断这个路径是否存在
        if not os.path.exists(curPath + '/report'):
            os.makedirs(curPath + '/report')
            time.sleep(1)
        with open(filename, 'wb') as report:
            runner = HwTestReport.HTMLTestReport(stream=report, verbosity=2,
                                                 title='中央财务理财系统',
                                                 description='中央财务理财系统自动化接口测试',
                                                 tester='杜志远')
            runner.run(suite)
        leaderList=["1542043226@qq.com"]
        attach_list=[filename]
        Common.sendEmail("1542043226@qq.com",leaderList,"中央财务理财系统测试报告","中央财务理财系统",attach_list)

if __name__ == "__main__":
    program = Program()

